import { loginAPI, loginFromDataType, sendCodeAPI } from '@/api/login';
import { setToken } from '@/utils/storage';
import { AppDispatch } from '../reducer';

/** 发送验证码 Action*/
export function sendCodeAction(mobile: string) {
  return async () => {
    let res = await sendCodeAPI(mobile);
    console.log(res);
  };
}

/** 登录 Action*/
export function loginAction(fromDate: loginFromDataType) {
  return async (dispatch: AppDispatch) => {
    let { data } = await loginAPI(fromDate);
    // 存储token
    setToken(data);
    // console.log(res);
    dispatch({ type: 'user/saveAuth', payload: data });
  };
}
